********************************************************************************
**** Scholten & Leblang *** World Politics *** Last updated July 26, 2023 ******
********************************************************************************
*************** Land/Labor Ratios, Citizenship, and Migrants *******************
********************************************************************************

*** !!! Make sure to set wd where data is stored !!! ***

********************************************************************************
								/// 1975 Data \\\

use pwt1001.dta, clear

save working75.dta, replace

keep if year==1975
keep countrycode country year pop emp rnna 

save working75.dta, replace

import delimited "citlaws.xls - Data.csv", clear 

rename code countrycode

merge 1:1 countrycode using working75.dta
keep if _merge==3
drop _merge
save working75.dta, replace

import excel "arable.xls", sheet("Data") firstrow clear
keep CountryName CountryCode R 
rename CountryName country
rename CountryCode countrycode 
rename R land

merge 1:1 countrycode using working75.dta
keep if _merge==3
drop _merge
save working75.dta, replace

gen landlab = land/pop
gen loglandlab = log(landlab)
gen caplab = rnna/emp
gen logcaplab = log(caplab)

gen idealcit75 = citlaws75 
recode idealcit75 2=1
recode idealcit75 1=0 3=1

ologit citlaws75 loglandlab logcaplab civil latam ssa // Model 1 (table 1)

qui margins, at(loglandlab=(7(1)14)) // Figure 1.1
marginsplot, ///
	plot1(m(D) mc(gs1) mlc(gs1) lc(gs1)) ///
	plot2(m(T) mc(gs6) mlc(gs6) lc(gs6)) ///
	plot3(m(X) mc(gs11) mlc(gs11) lc(gs11) msize(medlarge)) ///
	ci1(lc(gs1)) ci2(lc(gs6)) ci3(lc(gs11)) ///
	title("LL-Ratio, Cit. 1975", color(black)) ///
	leg(off order(1 3 2) lab(1 "Sanguinis") lab(2 "Mixed") lab(3 "Soli") r(1)) ///
	xti("Land/Labor Ratio") ///
	ylab(, angle(0)) graphr(c(white)fc(white)lc(white)) ///
	plotr(c(white)fc(white)lc(white)) ///
	scheme(s2mono) ///
	yscale(range(0(0.2)1)) ylab(0(0.2)1) ///
	saving(margins1.gph, replace)

qui margins, at(civil=(0(1)1)) // Figure 1.2
marginsplot, ///
	plot1(m(D) mc(gs1) mlc(gs1) lc(gs1)) ///
	plot2(m(T) mc(gs6) mlc(gs6) lc(gs6)) ///
	plot3(m(X) mc(gs11) mlc(gs11) lc(gs11) msize(medlarge)) ///
	ci1(lc(gs1)) ci2(lc(gs6)) ci3(lc(gs11)) ///
	title("Civil Law, Cit. 1975", color(black)) ///
	leg(off order(1 3 2) lab(1 "Sanguinis") lab(2 "Mixed") lab(3 "Soli") r(1)) ///
	xti("Civil Law") ///
	ylab(, angle(0)) graphr(c(white)fc(white)lc(white)) ///
	plotr(c(white)fc(white)lc(white)) ///
	scheme(s2mono) ///
	yscale(range(0(0.2)1)) ylab(0(0.2)1) ///
	saving(margins2.gph, replace)


ologit citlaws75 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol4875 obc4875 // Model 1.1 (full B&S controls) (Appendix)
ologit citlaws75 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol7601 obc7601 // Model 1.2 (full B&S controls) (Appendix)
logit idealcit75 loglandlab logcaplab civil latam ssa // Model 1.3 (ideal type, mixed = sanguinis) (Appendix)
logit idealcit75 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol7601 obc7601 // Model 1.4 (ideal type, full B&S controls) (Appendix)


********************************************************************************
								/// 2001 Data \\\

use pwt1001.dta, clear

save working01.dta, replace

keep if year==2001
keep countrycode country year pop emp rnna 

save working01.dta, replace

import delimited "citlaws.xls - Data.csv", clear 

rename code countrycode

merge 1:1 countrycode using working01.dta
keep if _merge==3
drop _merge
save working01.dta, replace

import excel "arable.xls", sheet("Data") firstrow clear
keep CountryName CountryCode AR 
rename CountryName country
rename CountryCode countrycode 
rename AR land

merge 1:1 countrycode using working01.dta
keep if _merge==3
drop _merge
save working01.dta, replace

gen landlab = land/pop
gen loglandlab = log(landlab)
gen caplab = rnna/emp
gen logcaplab = log(caplab)

gen idealcit01 = citlaws01 
recode idealcit01 2=1
recode idealcit01 1=0 3=1

ologit citlaws01 loglandlab logcaplab civil latam ssa // Model 2 (table 1)

qui margins, at(loglandlab=(7(1)14)) // Figure 1.3
marginsplot, ///
	plot1(m(D) mc(gs1) mlc(gs1) lc(gs1)) ///
	plot2(m(T) mc(gs6) mlc(gs6) lc(gs6)) ///
	plot3(m(X) mc(gs11) mlc(gs11) lc(gs11) msize(medlarge)) ///
	ci1(lc(gs1)) ci2(lc(gs6)) ci3(lc(gs11)) ///
	title("LL-Ratio, Cit. 2001", color(black)) ///
	leg(off order(1 3 2) lab(1 "Sanguinis") lab(2 "Mixed") lab(3 "Soli") r(1)) ///
	xti("Land/Labor Ratio") ///
	ylab(, angle(0)) graphr(c(white)fc(white)lc(white)) ///
	plotr(c(white)fc(white)lc(white)) ///
	scheme(s2mono) ///
	yscale(range(0(0.2)1)) ylab(0(0.2)1) ///
	saving(margins3.gph, replace)

qui margins, at(civil=(0(1)1)) // Figure 1.4
marginsplot, ///
	plot1(m(D) mc(gs1) mlc(gs1) lc(gs1)) ///
	plot2(m(T) mc(gs6) mlc(gs6) lc(gs6)) ///
	plot3(m(X) mc(gs11) mlc(gs11) lc(gs11) msize(medlarge)) ///
	ci1(lc(gs1)) ci2(lc(gs6)) ci3(lc(gs11)) ///
	title("Civil Law, Cit. 2001", color(black)) ///
	leg(off order(1 3 2) lab(1 "Sanguinis") lab(2 "Mixed") lab(3 "Soli") r(1)) ///
	xti("Civil Law") ///
	ylab(, angle(0)) graphr(c(white)fc(white)lc(white)) ///
	plotr(c(white)fc(white)lc(white)) ///
	scheme(s2mono) ///
	yscale(range(0(0.2)1)) ylab(0(0.2)1) ///
	saving(margins4.gph, replace)

***net install grc1leg,from( http://www.stata.com/users/vwiggins/)	
grc1leg margins1.gph margins2.gph margins3.gph margins4.gph, /// Figure 1
	ycommon commonscheme scheme(s2mono) ///
	graphr(c(white)fc(white)lc(white)) plotr(c(white)fc(white)lc(white)) ///
	legendfrom(margins1.gph) ///
	saving(margin_merge.png, asis replace)
	
ologit citlaws01 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol4875 obc4875 // Model 2.1 (full B&S controls) (Appendix)
ologit citlaws01 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol7601 obc7601 // Model 2.2 (full B&S controls) (Appendix)
logit idealcit01 loglandlab logcaplab civil latam ssa // Model 2.3 (ideal type) (Appendix)
logit idealcit01 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol7601 obc7601 // Model 2.4 (ideal type, full B&S controls) (Appendix)


ologit natur01 loglandlab logcaplab civil latam ssa // Model 3 (table 1)
ologit natur01 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol4875 obc4875 // Model 3.1 (full B&S controls) (Appendix)
ologit natur01 loglandlab logcaplab civil latam ssa smallc socialist oil britprtcol bw southeu decol7601 obc7601 // Model 3.2 (full B&S controls) (Appendix)
